from rest_framework import serializers
from .models import PhoneChangeRequest

class SendSMSSerializer(serializers.Serializer):
    phone = serializers.CharField(max_length=11)
    
    def validate_phone(self, value):
        if not value.isdigit() or len(value) != 11:
            raise serializers.ValidationError("手机号格式不正确")
        return value

class VerifyCodeSerializer(serializers.Serializer):
    phone = serializers.CharField(max_length=11)
    code = serializers.CharField(max_length=6)
    
    def validate(self, data):
        if not data['phone'].isdigit() or len(data['phone']) != 11:
            raise serializers.ValidationError({"phone": "手机号格式不正确"})
        if not data['code'].isdigit() or len(data['code']) != 6:
            raise serializers.ValidationError({"code": "验证码必须为6位数字"})
        return data